﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Qianwei.Model;
using Qianwei.Dac;
using Qianwei.Common;
using Qianwei.Common.Extension;
using MySql.Data.MySqlClient;

namespace Qianwei.Biz
{
    public class ResumeInfoManager : ManagerBase<ResumeInfoManager>
    {
        public IList<resume_info> QueryProductInfo(string strWhere)
        {
            MySQLHelper msh = new MySQLHelper();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM resume_info ");
            if (strWhere != null && strWhere.Trim().Length > 0)
            {
                strSql.Append(" where " + strWhere);
            }
            IList<resume_info> rilist = Mapper.DataReaderToList<resume_info>(msh.ExecuteReader(strSql.ToString()));
            return rilist;
        }

        public IList<resume_info> QueryProductInfo(string strWhere, string filedOrder)
        {
            MySQLHelper msh = new MySQLHelper();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ri.*,ji.Job_Position ");
            strSql.Append(" FROM resume_info ri ");
            strSql.Append(" left join job_info ji on ji.Job_Id=ri.Job_Id");
            if (strWhere != null && strWhere.Trim().Length > 0)
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            IList<resume_info> rilist = Mapper.DataReaderToList<resume_info>(msh.ExecuteReader(strSql.ToString()));
            return rilist;
        }

        public int Add(resume_info model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into resume_info(");
            strSql.Append("Job_Id,User_Name,Sex,Birthday,Marital_Status,University,Education,Professional,Graduation_Time,TelePhone,Email,Contact_Address,Ability_Level,Personal_Resume,Create_Time");
            strSql.Append(") values (");
            strSql.Append("@Job_Id,@User_Name,@Sex,@Birthday,@Marital_Status,@University,@Education,@Professional,@Graduation_Time,@TelePhone,@Email,@Contact_Address,@Ability_Level,@Personal_Resume,@Create_Time");
            strSql.Append(") ");
            strSql.Append(";SELECT LAST_INSERT_ID();");
            MySqlParameter[] parameters = {
                        new MySqlParameter("Job_Id", model.Job_Id),
                        new MySqlParameter("@User_Name", model.User_Name) ,            
                        new MySqlParameter("@Sex", model.Sex) ,            
                        new MySqlParameter("@Birthday", model.Birthday) ,            
                        new MySqlParameter("@Marital_Status", model.Marital_Status) ,            
                        new MySqlParameter("@University", model.University) ,            
                        new MySqlParameter("@Education", model.Education) ,            
                        new MySqlParameter("@Professional", model.Professional) ,            
                        new MySqlParameter("@Graduation_Time", model.Graduation_Time) ,            
                        new MySqlParameter("@TelePhone", model.TelePhone) ,            
                        new MySqlParameter("@Email", model.Email) ,            
                        new MySqlParameter("@Contact_Address", model.Contact_Address) ,            
                        new MySqlParameter("@Ability_Level", model.Ability_Level) ,            
                        new MySqlParameter("@Personal_Resume", model.Personal_Resume) ,            
                        new MySqlParameter("@Create_Time", DateTime.Now)             
              
            };

            MySQLHelper msh = new MySQLHelper();
            object obj = msh.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        public bool Delete(int Resume_Id)
        {
            MySQLHelper msh = new MySQLHelper();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from resume_info ");
            strSql.Append(" where Resume_Id=@Resume_Id");
            MySqlParameter[] parameters = {
					new MySqlParameter("@Resume_Id", (object)Resume_Id)
            };

            int rows = msh.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
